package com.atguigu.tingshu.user.factory.impl;

import com.atguigu.tingshu.common.execption.GuiguException;
import com.atguigu.tingshu.user.factory.StrategyFactory;
import com.atguigu.tingshu.user.strategy.ItemTypeStrategy;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Map;

/**
 * projectName: com.atguigu.tingshu.user.factory
 *
 * @author: 吴振鹏
 * description:
 * time: 2025/9/16 19:16
 */
@Slf4j
@Component
public class StrategyFactoryImpl implements StrategyFactory {
    @Autowired
    private Map<String, ItemTypeStrategy> strategyMap;
    @Override
    public ItemTypeStrategy getStrategy(String itemType) {
        if (strategyMap.containsKey(itemType)) {
            return strategyMap.get(itemType);
        }
        log.error("该策略实现类不存在");
        throw new GuiguException(500, "该策略" + itemType + "实现类不存在");
    }
}
